package A1_贪心算法;

public class LC_45跳跃游戏II_1 {
    public static void main(String[] args){
        int[] nums={1,2};
        int res=jump(nums);
        System.out.println(res);
    }
    public static int jump(int[] nums) {
        if(nums.length == 1 || nums.length == 0||nums==null)
            return 0;
        int cur=0;
        int next=0,result=0;
        for(int i=0;i<nums.length;i++){
            next=Math.max(i+nums[i],next);
            if(next>=nums.length-1){
                result++;
                break;
            }
            if(i==cur){
                cur=next;
                result++;
            }
        }
        return result;
    }
}
